import { getStorage, setStorage, removeStorage } from '../../assets/js/storage.js';
import axios from '../../utils/request';
import api from '../../utils/apijs';
// import { data } from 'jquery';
export default {
  // namespaced: true,
  state: {
    user: getStorage('user') || {},
    dangqianye: 1,
    medical: [],
    shenfen: [],
    bill: [],
    top: [],
    qiankuan: [],
    stu: [],
    ter: [],
  },
  getters: {
    username(state) {
      state.user.xingMing;
    },
    usermsg(state) {
      state.user;
    },
    //当前页医疗卡
    dangqianyeMe: state => state.medical.slice((state.dangqianye - 1) * 5, (state.dangqianye - 1) * 5 + 5),
    //医疗卡最大页码
    maxPgeMe: state => Math.ceil(state.medical.length / 5),

    shenfendata: state => state.shenfen,

    //当前页代扣账单
    dangqianyeBill: state => state.bill.slice((state.dangqianye - 1) * 5, (state.dangqianye - 1) * 5 + 5),
    //代扣账单最大页码
    maxPgeBill: state => Math.ceil(state.bill.length / 5),

    //当前页充值
    dangqianyeTOP: state => state.top.slice((state.dangqianye - 1) * 5, (state.dangqianye - 1) * 5 + 5),
    //充值最大页码
    maxPgeTOP: state => Math.ceil(state.top.length / 5),

    //当前页欠款
    dangqianyeqiank: state => state.qiankuan.slice((state.dangqianye - 1) * 5, (state.dangqianye - 1) * 5 + 5),
    //欠款最大页码
    maxPgeqiank: state => Math.ceil(state.qiankuan.length / 5),
  },
  mutations: {
    muALLmedical(state, data) {
      state.medical = data;
    },
    muDangqianye(state, page) {
      state.dangqianye = page;
    },
    mushenfen(state, data) {
      state.shenfen = data;
    },
    muALLbill(state, data) {
      state.bill = data;
    },
    muAlltop(state, data) {
      state.top = data;
    },
    muqian(state, data) {
      state.qiankuan = data;
    },
    mustu(state, data) {
      state.stu = data;
    },
    muter(state, data) {
      state.ter = data;
    },
  },
  actions: {
    //查询所有医疗卡
    getALL(context, obj) {
      return api[obj.name](obj.data).then(data => {
        console.log(data);
        console.log(data.data.data);
        context.commit('muALLmedical', data.data.data);
      });
    },
    //查询所有身份
    getShen(context, obj) {
      return api[obj.name](obj.data).then(data => {
        console.log(data);
        context.commit('mushenfen', data.data.data);
      });
    },
    //确定增加医疗卡
    queaddme(context, obj) {
      return axios(obj).then(data => {
        console.log(1);
        console.log(data);
        return data.data.code;
      });
    },
    //确定修改
    quedingXiuGia(context, obj) {
      return axios(obj).then(data => {
        console.log(data);
        console.log(obj);
        return data.data.code;
      });
    },
    //查询
    findMe(context, obj) {
      return api[obj.name](obj.data).then(data => {
        console.log(data);
        context.commit('muALLmedical', [data.data.data]);
        return data.data.code;
      });
    },
    //查询所有代扣账单
    getALLBill(context, obj) {
      return api[obj.name](obj.data).then(data => {
        console.log(data.data.data);
        context.commit('muALLbill', data.data.data);
      });
    },
    //单个查询代扣计费表账单
    findBill(context, obj) {
      return api[obj.name](obj.data).then(data => {
        console.log(data.data.data);
        context.commit('muALLbill', data.data.data);
        return data.data.data;
      });
    },
    //查询所有充值记录
    getAllTopup(context, obj) {
      return api[obj.name](obj.data).then(data => {
        console.log(data);
        context.commit('muAlltop', data.data.data);
      });
    },
    //充值条件查询
    findtopup(context, obj) {
      return axios(obj).then(data => {
        console.log(obj);
        console.log(1);
        console.log(data);
        context.commit('muAlltop', data.data.data);
        return data.data.code;
      });
    },
    //欠款人员查询
    getqian(context, obj) {
      return axios(obj).then(data => {
        console.log(data.data.data);
        context.commit('muqian', data.data.data);
      });
    },
    //删除
    delet(context, obj) {
      return axios(obj).then(data => {
        return data.data.code;
      });
    },
    //充值操作
    chongzhiadd(context, obj) {
      return axios(obj).then(data => {
        console.log(data);
        console.log(1);
        console.log(obj);
        return data.data.code;
      });
    },
    //查询所有学生学号
    getStu(context, obj) {
      return api[obj.name](obj.data).then(data => {
        console.log(data.data.data);
        context.commit('mustu', data.data.data);
        return data.data.code;
      });
    },
    //查询所有教职工号
    getter(context, obj) {
      return api[obj.name](obj.data).then(data => {
        console.log(data.data.data);
        context.commit('muter', data.data.data);
        return data.data.code;
      });
    },
    //挂失
    getguashi(context, obj) {
      return axios(obj).then(data => {
        console.log(data);
        return data.data.code;
      });
    },
  },
  modules: {},
};
